<template>
	<view class="home_continue">
		<view class="search_box">
			<my-search @myclick="gotoSearch"></my-search>
		</view>
		<!-- 轮播图区域 -->
		<swiper class="swiper" interval="2000" indicator-dots="true" autoplay="true"  indicator-color="#ffffff" indicator-active-color="#c00000">
			<swiper-item v-for="(item,i) in swiperData" :key="i">
				<navigator open-type="navigate"  :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id" class="swiper-item">
					<image class="img" :src="item.image_src" mode="aspectFill"></image>
				</navigator>
			</swiper-item>
		</swiper>
		
		<!-- 分类导航区域 -->
		<view class="cate">
			<view class="cate-item" @click="handleCate(item)" v-for="(item,index) in navList" :key="index">
				<image :src="item.image_src"></image>
			</view>
		</view>
		
		<!-- 楼层区域 -->
		<view class="floor">
			<!-- 楼层区域 -->
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<!-- 楼层标题 -->
				<view class="floor-title">
					<image :src="item.floor_title.image_src"mode="aspectFit"></image>
				</view>
				<!-- 楼层照片 -->
				<view class="floor-img">
					<!-- 左侧照片 -->
					<navigator open-type="navigate" :url="item.product_list[0].url" class="left">
						<image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="right">
						<navigator open-type="navigate" :url="item2.url" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2 !== 0">
							<image :src="item2.image_src" :style="{width: item2.image_width + 'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import badgeMix from '@/mixins/badge-tabbar.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				// 轮播图数据
				swiperData:[],
				// 分类数据
				navList:[],
				// 楼层数据
				floorList:[]
			}
		},
		onLoad() {
			this.getSwiper()
			this.getNav()
			this.getFloorList()
		},
		methods: {
			// 获取轮播图数据
			async getSwiper() {
				const {data:res} = await uni.$http.get('public/v1/home/swiperdata')
				// console.log(res)
				if(res.meta.status !== 200){
					return uni.showMsg()
				}
				this.swiperData = res.message
				uni.showMsg('数据请求成功')
			},
			// 获取分类数据
			async getNav() {
				const {data} = await uni.$http.get('public/v1/home/catitems')
				if(data.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.navList = data.message
			},
			handleCate(item) {
				// console.log(item)
				if(item.name === '分类'){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			// 获取楼层数据
			async getFloorList() {
				const {data} = await uni.$http.get('public/v1/home/floordata')
				// console.log(data)
				if(data.meta.status !== 200) {
					return uni.$showMsg()
				}
				data.message.forEach(floor => {
					floor.product_list.forEach(prod => {
						prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
					})
				})
				this.floorList = data.message
			},
			gotoSearch() {
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
 /* 轮播图样式 */
 swiper{
	 height:330rpx;
	 
	 .swiper-item,
	 image{
		 width: 100%;
		 height: 100%;
	 }
 }
 // 分类导航样式
 .cate{
	 width: 100%;
	 height: auto;
	 display: flex;
	 flex-direction:row;
	 justify-content: space-around;
	 align-items: center;
	 margin: 15rpx;
 }
 .cate-item>image{
	 width: 110rpx;
	 height:110rpx;
 }
 // 楼层区域样式
 .floor-title{
	 width: 100%;
	 height: 90rpx;
	 image{
		 width: 100%;
		 height: 100%;
		 margin-top: 10rpx;
	 }
 }
.floor-img{
	display: flex;
	.right{
		display: flex;
		flex-wrap: wrap;
		image{
			margin: 7rpx;
		}
	}
}
// 导航组件吸顶效果
.search_box{
	position: sticky;
	top: 0px;
	z-index: 999;
}
</style>
